package com.car.service;

import com.car.dao.CarDao;
import com.car.dao.EmployeeDao;
import com.car.dao.impl.CarDaoImpl;
import com.car.dao.impl.EmployeeDaoImpl;
import com.car.domain.Car;
import com.car.domain.Employee;
import com.car.utils.NumberUtil;

import java.util.Scanner;

public class EmployeeService {
     private  static final EmployeeDao employeeDao = new EmployeeDaoImpl();
     private  static  final CarDao carDao= new CarDaoImpl();
    public Employee login(Scanner scanner) throws Exception {
        System.out.println("员工登录");
        System.out.println("请输入员工的工号");
        String workId = scanner.next();
        System.out.println("请输入密码");
        String password = scanner.next();
        Employee employee = employeeDao.findByWorkId(workId);
        if (employee == null  || ! "123456".equals(password)){
            System.out.println("登录失败");
            return  null;
        }
        return  employee;
    }

    public void addCar(Employee employee, Scanner scanner) throws Exception {
        System.out.println("汽车上架");
        Car car = new Car();
        System.out.println("请输入汽车的名字");
        String name = scanner.next();
        car.setName(name);

        System.out.println("请输入汽车的品牌");
        String brand = scanner.next();
        car.setBrand(brand);

        System.out.println("请输入汽车的颜色");
        String color= scanner.next();
        car.setColor(color);

        System.out.println("请输入汽车的类型");
        String type  = scanner.next();
        car.setType(type);

        System.out.println("请输入汽车的价格");
        double price=scanner.nextDouble();
        car.setPrice(price);
        car. setCarNum(NumberUtil.generateCardNum());
        car.setEmployeeId(employee.getId());
        int i = carDao.add(car);
        if (i>0){
            System.out.println("上架成功");
        }else {
            System.out.println("操作失败");
        }

    }
}
